package zzxkj.blog.controller;

import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zzxkj.blog.common.lang.Consts;
import zzxkj.blog.common.lang.Result;
import zzxkj.blog.imChat.vo.ImUser;
import zzxkj.blog.service.ChatService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 聊天室
 * @author zzxkj
 */
@Slf4j
@RestController
@RequestMapping("/chat")
public class ChatController {
    final
    ChatService chatService;

    public ChatController(ChatService chatService) {
        this.chatService = chatService;
    }

    @GetMapping("/getMineAndGroupData")
    public Result getMineAndGroupData(){
        //群
        Map<String, Object> group = new HashMap<>();
        group.put("name", "博客群聊室");
        group.put("type", "group");
        group.put("avatar", "/chat.png");
        group.put("id", Consts.IM_DEFAULT_USER_ID);
        group.put("members", 0);
        ImUser user = chatService.getCurrentUser();
        Result result = Result.success(MapUtil.builder().put("group", group).put("mine", user).map());
        log.info(result.toString());
        return result;
    }

    /**
     * 获得群历史聊天记录
     * @return
     */
    @GetMapping("/getGroupHistoryMsg")
    public Result getGroupHistoryMsg() {
        List<Object> messages = chatService.getGroupHistoryMsg(20);
        return Result.success(messages);
    }
}
